package com.topgay.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.topgay.dao.CSCenterDAO;
import com.topgay.domain.CSCenter;
import com.topgay.domain.Declaration;
import com.topgay.util.BoardUtilities;

@Service
public class CSCenterServiceImpl implements CSCenterService{

	@Autowired
	private CSCenterDAO cSCenterDAO; 
	
	@Override
	public List<CSCenter> getCSCenterList(int page, int divide) {
		
//		1. DAO메소드를 이용해 매개변수로 받은 페이지에 보여줄 게시물들을 ArrayList로 조회
		return cSCenterDAO.selectCSCenterList(page, divide);
	}
	
	@Override
	public int getTotalContent(int divide) {
		return cSCenterDAO.selectTotalContent(divide);
	}

	@Override
	public void setWriteContent(CSCenter cscenter) {
		
		//1. 입력일시와 사용자가 입력한 글의 내용을 DB용으로 변환한 것을 매개변수로 받은 board에 설정한다.
		String content = BoardUtilities.changeContentForDB(cscenter.getContent());
		cscenter.setContent(content);
		//2. DAO를 이용해 글을 DB에 등록한다.
		cSCenterDAO.insertCSCenterContent(cscenter, 5);
	}
	
	@Override
	public CSCenter getCSCenterContentByNo(int cscenterNo) {
		
		//1. DAO의 메소드를 이용해 조회수를 1 증가 시킨다.
		cSCenterDAO.updateCSCenterViewCount(cscenterNo);
		CSCenter cscenter = cSCenterDAO.selectCSCenterContentByNo(cscenterNo);
		return cscenter;
	}

	@Override
	public CSCenter getCSCenterContentByNoNotViewCount(int cscenterNo) {
		
		//1. DAO의 메소드를 이용해 조회수를 증가 없음.
		CSCenter cscenter = cSCenterDAO.selectCSCenterContentByNo(cscenterNo);
		return cscenter;
	}
	
	@Override
	public CSCenter getContentByNoForForm(int cscenterNo) {
		CSCenter cscenter = cSCenterDAO.selectCSCenterContentByNo(cscenterNo);
		cscenter.setContent(BoardUtilities.changeContentForTextArea(cscenter.getContent()));
		return cscenter;
	}

	@Override
	public void modifyContent(CSCenter cscenter) {
		cscenter.setContent(BoardUtilities.changeContentForDB(cscenter.getContent()));
		cSCenterDAO.updateCSCenterContent(cscenter);
	}

	@Override
	public void deleteContentByNo(int cscenterNo) {
		cSCenterDAO.deleteContentByNO(cscenterNo);
	}

	
	@Override
	public int getDeclarationTotalContent() {
		return cSCenterDAO.selectDeclarationTotalContent();
	}
	
	@Override
	public void setWriteDeclarationContent(Declaration declaration) {
		cSCenterDAO.insertDeclarationContent(declaration);
	}

	@Override
	public List<Declaration> getDeclarationList(int page) {
		return cSCenterDAO.selectDeclarationList(page);
	}

	@Override
	public List<Declaration> getDeclarationListByAssaulterId(int page, String assaulterId) {
		return cSCenterDAO.selectDeclarationListByAssaulterId(page, assaulterId);
	}

	@Override
	public List<Declaration> getDeclarationListByAssaulterNickname(int page, String assaulterNickname) {
		return cSCenterDAO.selectDeclarationListByAssaulterNickname(page, assaulterNickname);
	}

	@Override
	public List<Declaration> getDeclarationListById(int page, String id) {
		return cSCenterDAO.selectDeclarationListById(page, id);		
	}

	@Override
	public Declaration getDeclarationContentByNo(int declarationNo) {
		return cSCenterDAO.selectDeclarationContentByNo(declarationNo);
	}

	@Override
	public void modifyDeclarationForResult(int declarationNo, String result) {
		cSCenterDAO.updateDeclarationForResult(declarationNo, result);
	}

	@Override
	public void deleteDeclarationContentByNo(int declarationNo) {
		cSCenterDAO.deleteDeclarationContentByNo(declarationNo);
	}
	
}
